package main

func main() {

}

type ListNode struct {
	Val  int
	Next *ListNode
}

//#link: https://leetcode-cn.com/problems/split-linked-list-in-parts/
func splitListToParts(head *ListNode, k int) []*ListNode {
	hLen := 0
	for temp := head; temp != nil; temp = temp.Next {
		hLen++
	}
	ans := make([]*ListNode, k)
	pre, mod := hLen/k, hLen%k
	for i, curr := 0, head; i < k && curr != nil; i++ {
		ans[i] = curr
		partSize := pre
		if i < mod {
			partSize++
		}
		for j := 1; j < partSize; j++ {
			curr = curr.Next
		}
		curr, curr.Next = curr.Next, nil
	}

	return ans
}
